package com.waypolice.common.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * 描述:
 *      应用于普通类中调用spring管理的bean方法
 * @author zyp
 * @description 应用application获取bean对象
 * @create 2018-08-24 8:52
 */
public class ApplicationContextUtil implements ApplicationContextAware {

    private static ApplicationContext appCtx = null;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        appCtx = applicationContext;
    }

    public static ApplicationContext getApplicationContext(){
        return appCtx;
    }

    public static Object getBean(String beanName){
        return getApplicationContext().getBean(beanName);
    }

    public static Object getBean(Class c){
        return getApplicationContext().getBean(c);
    }
}